<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="./vue.js"></script>
    <style>
        .box1 {
            height: 100px;
            width: 100px;
        }

        .green {
            background-color: green;
        }

        .border {
            border: 1px solid;
        }
    </style>
</head>

<body>
    <div id="app">
        <!-- 字符串绑定 :用于单个的类名判断 -->
        <div class="box1" :class="isClass?'green':null"></div>
        <div class="box1" :class="classe"></div>
        <!-- 对象绑定 :用于已知类名数量,直接控制类名后的布尔值 -->
        <div class="box1" :class="ClassName"></div>
        <!-- 数组绑定 :用于未知类名数量,可以使用数组方法动态的添加-->
        <div class="box1" :class="ClassArray"></div>
    </div>
    <script>
        Vue.config.productionTip = false;
        const vm = new Vue({
            el: "#app",
            data() {
                return {
                    isClass: true,
                    classe: 'green',
                    ClassName: { green: true, border: false },
                    ClassArray: ['green', 'border']//数组内为字符串,也可以为变量
                };
            },
        });
    </script>
</body>

</html>